package bizlogic;

import java.util.ArrayList;

import model.LeaveDTO;
import exception.DAOSystemException;
import dao.DAOFactory;
import dao.LeaveDAO;


public class LeaveManager {
	private LeaveDAO leaveDAO;
	public LeaveManager() {
		leaveDAO = DAOFactory.loadInstance().getLeaveDAO();
	}

	@SuppressWarnings("finally")
	public LeaveDTO findLeave(String id){
		LeaveDTO currentLeave = new LeaveDTO();
		try {
			currentLeave = leaveDAO.findLeave(id);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally
		{
			return currentLeave;
		}
		
	}
    @SuppressWarnings("finally")
	public ArrayList<LeaveDTO> findAllLeave() throws DAOSystemException {
    	ArrayList<LeaveDTO> currentList = new ArrayList<LeaveDTO>();

			currentList = leaveDAO.findAllLeaves();

			return currentList;

    }
    
    public void insertLeave(LeaveDTO leave) {
    	try {
			leaveDAO.insertLeave(leave);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    public void updateLeave(LeaveDTO leave) {
    	try {
			leaveDAO.updateLeave(leave);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
   
    public void deleteLeave(LeaveDTO leave) {
    	try {
    		leaveDAO.deleteLeave(leave);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    @SuppressWarnings("finally")
	public ArrayList<LeaveDTO> findAllLeaveByManagerId(String userId) {
    	ArrayList<LeaveDTO> currentList = new ArrayList<LeaveDTO>();
		try {
			currentList =leaveDAO.findAllLeaveByManagerID(userId);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		finally
		{
			return currentList;
		} 
    }
    
    @SuppressWarnings("finally")
	public LeaveDTO findLeaveDetailByID(String leaveId) {
        LeaveDTO leave=new LeaveDTO();
   		try {
   			
   			leave =leaveDAO.findLeaveDetailByID(leaveId);
   		} catch (DAOSystemException e) {
   			// TODO Auto-generated catch block
   			e.printStackTrace();
   		} 
   		finally
   		{
   			return leave;
   		}
       	 
       }
    
	@SuppressWarnings("finally")
	public ArrayList<LeaveDTO> findAllSubordinateByManagerId(String mgrId) {
		ArrayList<LeaveDTO> currentList = new ArrayList<LeaveDTO>();
		try {
			
			currentList =leaveDAO.findAllSubordinateByManagerId(mgrId);
		} catch (DAOSystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		finally
		{
			return currentList;
		}
   	 
    }
	
	public void UpdateLeave(String id, String status, String reason) {
		try {
			
			leaveDAO.UpdateLeave(id,status,reason);
			} catch (DAOSystemException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			finally
			{
				
			}
	}

	@SuppressWarnings("finally")
	public ArrayList<LeaveDTO> findAllLeaveByUserId(String id) {
	    	ArrayList<LeaveDTO> currentList = new ArrayList<LeaveDTO>();
			try {
				
				currentList =leaveDAO.findAllLeaveByUserId(id);
			} catch (DAOSystemException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			finally
			{
				return currentList;
			}
	    	 
	    }
	
	   /* Start: Added By : Suganthi */
	   @SuppressWarnings("finally")
		public ArrayList<LeaveDTO> findAllLeaveByUser(String userid) {
	    	ArrayList<LeaveDTO> currentList = new ArrayList<LeaveDTO>();
			try {
				currentList = leaveDAO.findAllLeavesByUser(userid);
			} catch (DAOSystemException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} finally
			{
				return currentList;
			}
	    }
	   /* End: Added By : Suganthi */  
}
